﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Text;
using System.Configuration;
using ESMAM.Tools;
using ESMAM.Web.Core;
using ESMAM.Model;

namespace System.Web.Mvc
{
    public static class HtmlHelperExtension
    {
        public static string GetConfig(this HtmlHelper helper, string key)
        {
            return ConfigurationManager.AppSettings[key];
        }

        /// <summary>
        /// 当前语言下 对应的显示语言文字
        /// HtmlHelper + Cookie 实现 语言切换
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="fldName"></param>
        /// <returns></returns>
        public static string CurLang(this HtmlHelper helper, string textStr)
        {
            string res = null;
            string strLang = CookieHelper.GetCookieValue(BaseController.CONST_COOKIE_LANG);

            Lang lg = string.IsNullOrWhiteSpace(strLang) ? Lang.en : (Lang)Enum.Parse(typeof(Lang), strLang);

            if (lg == Lang.zh)
            {
                res = textStr;
            }
            else if (lg == Lang.en)
            {
                res = ESMAM.BLL.SYS.LangBLL.dict_CN_EN[textStr];
            }
            //else if (lg == Lang.jp)
            //{
            //    res = ESMAM.BLL.SYS.LangBLL.dict_CN_JP[textStr];
            //}
            //else if (lg == Lang.kor)
            //{
            //    res = ESMAM.BLL.SYS.LangBLL.dict_CN_KOR[textStr];
            //}
            else if (lg == Lang.spa)
            {
                res = ESMAM.BLL.SYS.LangBLL.dict_CN_SPA[textStr];
            }
            else
            {
                res = textStr;
            }
            return res ?? textStr;
        }


        public static string CurLangText(this HtmlHelper helper)
        {
            string res = null;
            string langType = CookieHelper.GetCookieValue(BaseController.CONST_COOKIE_LANG);
            if (langType == "en")
            {
                res = "English";
            }
            else if (langType == "zh")
            {
                res = "简体中文";
            }
            else if (langType == "kor")
            {
                res = "한국어";
            }
            else if (langType == "jp")
            {
                res = "日本語";
            }
            else if (langType == "spa")
            {
                res = "Español";
            }
            return res ?? "English";//实在没有找到，则用当前 字段名
        }


        /// <summary>
        /// 获取
        /// </summary>
        /// <returns></returns>
        //public static ShiYYYEnum GetShiYYYEnum(this HtmlHelper helper)
        //{
        //    return (ShiYYYEnum)Enum.Parse(typeof(ShiYYYEnum), CookieHelper.GetCookieValue(BaseController.CONST_COOKIE_LANGTYPE));
        //}


    }
}